import axios from "axios";

export const fakeNetwork = axios.create({
  baseURL: "http://localhost:3000",//json-server模拟后端数据
  timeout: 10000,
});

// 请求响应拦截还是自己写的
fakeNetwork.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 注意响应拦截器的写法，
fakeNetwork.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    return Promise.reject(error);
  }
);

/**
 * 注意写法：
 * axios.interceptors.request.use(
    (config) => {
      return config;
    },
    (error) => {
      return Promise.reject(error);
    }
  );

  axios.interceptors.response.use(
    (response) => {
      return response.data;
    },
    (error) => {
      return Promise.reject(error);
    }
  );
*/
